package com.example.yiwei.crm.json;

import com.example.yiwei.crm.entity.MessageEntity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by DHN on 2017/7/31.
 */

public class MessageJson {
    public static List<MessageEntity> getmessage(String result){
        List<MessageEntity> list;
        MessageEntity entity;
        try {
            JSONObject object = new JSONObject(result);
            JSONArray array = object.getJSONArray("list");
            list = new ArrayList<>();
            for (int i=0;i<array.length();i++){
                entity = new MessageEntity();
                JSONObject json=array.getJSONObject(i);
                if (json.has("XXB01")){
                    entity.setID(json.getInt("XXB01"));
                }
                if (json.has("XXB02")){
                    entity.setContent(json.getString("XXB02"));
                }
                if (json.has("XXB03")){
                    entity.setState(json.getInt("XXB03"));
                }
                if (json.has("XXB04")){
                    entity.setManger_name(json.getString("XXB04"));
                }
                if (json.has("KAA02")){
                    entity.setCustomer_name(json.getString("KAA02"));
                }
                if (json.has("CTS01L")){
                    entity.setTime(json.getString("CTS01L"));
                }
                list.add(entity);
            }
            return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static List<MessageEntity> getshmessage(String result){
        List<MessageEntity> list;
        MessageEntity entity;
        try {
            JSONObject object = new JSONObject(result);
            JSONArray array = object.getJSONArray("list");
            list = new ArrayList<>();
            for (int i=0;i<array.length();i++){
                entity = new MessageEntity();
                JSONObject json=array.getJSONObject(i);
                if (json.has("XXM01")){
                    entity.setID(json.getInt("XXM01"));
                }
                if (json.has("XXM02")){
                    entity.setContent(json.getString("XXM02"));
                }
                if (json.has("XXM03")){
                    entity.setState(json.getInt("XXM03"));
                }
                if (json.has("XXM04")){
                    entity.setManger_name(json.getString("XXM04"));
                }
                if (json.has("KAA02")){
                    entity.setCustomer_name(json.getString("KAA02"));
                }
                if (json.has("CTS01L")){
                    entity.setTime(json.getString("CTS01L"));
                }
                list.add(entity);
            }
            return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
}
